<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActsAsPriceHelper</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActsAsPriceHelper</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/lib/acts_as_price_helper_rb.html">
                lib/acts_as_price_helper.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000006">columns_in_cents</a>&nbsp;&nbsp;
      <a href="#M000007">columns_in_doubles</a>&nbsp;&nbsp;
      <a href="#M000003">test_acts_as_price_methods</a>&nbsp;&nbsp;
      <a href="#M000004">test_setter_in_cents</a>&nbsp;&nbsp;
      <a href="#M000005">test_setter_in_doubles</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000006" class="method-detail">
        <a name="M000006"></a>

        <div class="method-heading">
          <a href="#M000006" class="method-signature">
          <span class="method-name">columns_in_cents</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000006-source">
<pre>
     <span class="ruby-comment cmt"># File lib/acts_as_price_helper.rb, line 108</span>
108:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">columns_in_cents</span> 
109:     [<span class="ruby-identifier">:price_in_cents</span>, <span class="ruby-node">&quot;#{@column_name}_in_cents&quot;</span>]
110:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000007" class="method-detail">
        <a name="M000007"></a>

        <div class="method-heading">
          <a href="#M000007" class="method-signature">
          <span class="method-name">columns_in_doubles</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000007-source">
<pre>
     <span class="ruby-comment cmt"># File lib/acts_as_price_helper.rb, line 112</span>
112:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">columns_in_doubles</span>
113:     [<span class="ruby-identifier">:price</span>, <span class="ruby-ivar">@column_name</span>]
114:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000003" class="method-detail">
        <a name="M000003"></a>

        <div class="method-heading">
          <a href="#M000003" class="method-signature">
          <span class="method-name">test_acts_as_price_methods</span><span class="method-args">(column_name, seperator, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Test the acts_as_price plugin for the specified column_name and given
seperator.
</p>
<p>
Valid options:
</p>
<ul>
<li>model: Not just the model name, but a full object of the model

</li>
</ul>
<p>
EXAMPLE:
</p>
<ul>
<li><a href="ActsAsPriceHelper.html#M000003">test_acts_as_price_methods</a>
:price, &quot;,&quot;, :model =&gt; @fuel

</li>
</ul>
<p>
Note the you can also specify the model in a before block in your tests
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000003-source">
<pre>
    <span class="ruby-comment cmt"># File lib/acts_as_price_helper.rb, line 10</span>
10:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">test_acts_as_price_methods</span> <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">seperator</span>, <span class="ruby-identifier">options</span> = {}
11:     <span class="ruby-ivar">@acts_as_price_model</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:model</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:model</span>]
12:     
13:     <span class="ruby-ivar">@column_name</span> = <span class="ruby-identifier">column_name</span>
14:     <span class="ruby-identifier">columns_in_cents</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span>
15:       <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">column</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">price_in_cents</span>
16:     <span class="ruby-keyword kw">end</span>
17:     <span class="ruby-identifier">columns_in_doubles</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span>
18:       <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">column</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">price</span>
19:     <span class="ruby-keyword kw">end</span>
20:     
21:     <span class="ruby-comment cmt">#normal test for setter</span>
22:     <span class="ruby-identifier">test_setter_in_cents</span> <span class="ruby-value str">&quot;144&quot;</span>, <span class="ruby-identifier">seperator</span>
23:     <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">currency</span>
24:       <span class="ruby-identifier">currency</span> = <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">currency</span>
25:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-node">&quot;#{currency}. 1.41&quot;</span>, <span class="ruby-identifier">seperator</span>
26:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-node">&quot;#{currency}. 1,41&quot;</span>, <span class="ruby-identifier">seperator</span>
27: 
28:       <span class="ruby-comment cmt">#test for special cases</span>
29:       <span class="ruby-comment cmt">#test if 1.5 is returned as 1.50</span>
30:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-node">&quot;#{currency}. 1.5&quot;</span>, <span class="ruby-identifier">seperator</span>
31:       <span class="ruby-comment cmt">#test if 1,5 is returned as 1.50</span>
32:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-node">&quot;#{currency}. 1,5&quot;</span>, <span class="ruby-identifier">seperator</span>
33: 
34:       <span class="ruby-comment cmt">#test if float returns 2.05 correctly </span>
35:       <span class="ruby-comment cmt">#float can return 2.05 as 2.04 in some cases</span>
36:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-node">&quot;#{currency}. 2.05&quot;</span>, <span class="ruby-identifier">seperator</span>
37:       
38:       <span class="ruby-comment cmt">#float can return 2,05 as 2.04 in some cases</span>
39:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-node">&quot;#{currency}. 2,05&quot;</span>, <span class="ruby-identifier">seperator</span>
40:     <span class="ruby-keyword kw">else</span>
41:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-value str">&quot;1.41&quot;</span>, <span class="ruby-identifier">seperator</span>
42:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-value str">&quot;1,41&quot;</span>, <span class="ruby-identifier">seperator</span>
43: 
44:       <span class="ruby-comment cmt">#test for special cases</span>
45:       <span class="ruby-comment cmt">#test if 1.5 is returned as 1.50</span>
46:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-value str">&quot;1.5&quot;</span>, <span class="ruby-identifier">seperator</span>
47:       <span class="ruby-comment cmt">#test if 1,5 is returned as 1.50</span>
48:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-value str">&quot;1,5&quot;</span>, <span class="ruby-identifier">seperator</span>
49: 
50:       <span class="ruby-comment cmt">#test if float returns 2.05 correctly </span>
51:       <span class="ruby-comment cmt">#float can return 2.05 as 2.04 in some cases</span>
52:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-value str">&quot;2.05&quot;</span>, <span class="ruby-identifier">seperator</span>
53:       
54:       <span class="ruby-comment cmt">#float can return 2,05 as 2.04 in some cases</span>
55:       <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-value str">&quot;2,05&quot;</span>, <span class="ruby-identifier">seperator</span>
56:     <span class="ruby-keyword kw">end</span>
57:     
58:     <span class="ruby-comment cmt">#test an empty_setter</span>
59:     <span class="ruby-identifier">test_setter_in_cents</span> <span class="ruby-value str">&quot;&quot;</span>, <span class="ruby-identifier">seperator</span>
60:     <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-value str">&quot;&quot;</span>, <span class="ruby-identifier">seperator</span>
61:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000004" class="method-detail">
        <a name="M000004"></a>

        <div class="method-heading">
          <a href="#M000004" class="method-signature">
          <span class="method-name">test_setter_in_cents</span><span class="method-args">(cents, seperator)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
test if the setter sets the price correctly if price is given in integers
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000004-source">
<pre>
    <span class="ruby-comment cmt"># File lib/acts_as_price_helper.rb, line 64</span>
64:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">test_setter_in_cents</span> <span class="ruby-identifier">cents</span>, <span class="ruby-identifier">seperator</span>
65:     <span class="ruby-identifier">columns_in_cents</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">setter</span><span class="ruby-operator">|</span>
66:       <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{setter}=&quot;</span>, <span class="ruby-identifier">cents</span>)
67:       <span class="ruby-identifier">columns_in_cents</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">getter</span><span class="ruby-operator">|</span>
68:         <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">getter</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">cents</span>.<span class="ruby-identifier">to_i</span>
69:       <span class="ruby-keyword kw">end</span>
70:       <span class="ruby-identifier">columns_in_doubles</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">getter</span><span class="ruby-operator">|</span>
71:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cents</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
72:           <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">getter</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
73:         <span class="ruby-keyword kw">else</span>
74:           <span class="ruby-identifier">currency</span> = <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">currency</span>
75:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">currency</span>
76:             <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">getter</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">currency</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;. &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;%.2f&quot;</span>, (<span class="ruby-identifier">cents</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">100</span>).<span class="ruby-identifier">to_s</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;.&quot;</span>, <span class="ruby-identifier">seperator</span>)
77:           <span class="ruby-keyword kw">else</span>
78:             <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">getter</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;%.2f&quot;</span>, (<span class="ruby-identifier">cents</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">100</span>).<span class="ruby-identifier">to_s</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;.&quot;</span>, <span class="ruby-identifier">seperator</span>)
79:           <span class="ruby-keyword kw">end</span>
80:         <span class="ruby-keyword kw">end</span>
81:       <span class="ruby-keyword kw">end</span>
82:     <span class="ruby-keyword kw">end</span>
83:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="#M000005" class="method-signature">
          <span class="method-name">test_setter_in_doubles</span><span class="method-args">(double, seperator)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
test if the setter sets the price correctly if price is given in doubles
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000005-source">
<pre>
     <span class="ruby-comment cmt"># File lib/acts_as_price_helper.rb, line 86</span>
 86:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">test_setter_in_doubles</span> <span class="ruby-identifier">double</span>, <span class="ruby-identifier">seperator</span>
 87:     <span class="ruby-identifier">currency</span> = <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">currency</span>
 88:     <span class="ruby-identifier">double</span> = <span class="ruby-identifier">double</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-node">&quot;#{currency}. &quot;</span>, <span class="ruby-value str">&quot;&quot;</span>)
 89:     <span class="ruby-identifier">columns_in_doubles</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">setter</span><span class="ruby-operator">|</span>
 90:       <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{setter}=&quot;</span>, <span class="ruby-identifier">double</span>)
 91:       <span class="ruby-identifier">columns_in_cents</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">getter</span><span class="ruby-operator">|</span>
 92:         <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">getter</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> (<span class="ruby-identifier">double</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;,&quot;</span>, <span class="ruby-value str">&quot;.&quot;</span>).<span class="ruby-identifier">to_f</span> <span class="ruby-operator">*</span> <span class="ruby-value">100</span>).<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">to_i</span>
 93:       <span class="ruby-keyword kw">end</span>
 94:       <span class="ruby-identifier">columns_in_doubles</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">getter</span><span class="ruby-operator">|</span>
 95:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">double</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
 96:           <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">getter</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
 97:         <span class="ruby-keyword kw">else</span>
 98:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">currency</span>
 99:             <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">getter</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">currency</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;. &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;%.2f&quot;</span>, <span class="ruby-identifier">double</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;,&quot;</span>, <span class="ruby-value str">&quot;.&quot;</span>)).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;.&quot;</span>, <span class="ruby-identifier">seperator</span>)
100:           <span class="ruby-keyword kw">else</span>
101:             <span class="ruby-ivar">@acts_as_price_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">getter</span>).<span class="ruby-identifier">should</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;%.2f&quot;</span>, <span class="ruby-identifier">double</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;,&quot;</span>, <span class="ruby-value str">&quot;.&quot;</span>)).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;.&quot;</span>, <span class="ruby-identifier">seperator</span>)
102:           <span class="ruby-keyword kw">end</span>
103:         <span class="ruby-keyword kw">end</span>
104:       <span class="ruby-keyword kw">end</span>
105:     <span class="ruby-keyword kw">end</span>
106:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>